<%@ page import="entity.User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: teacher
  Date: 2023/10/25
  Time: 9:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>EL表达式</title>
</head>
<body>
<%
    // 模拟Servlet存储数据,此处代码认为在Servlet中
    pageContext.setAttribute("msg","Hello pageContext");
    request.setAttribute("msg","Hello request");
    session.setAttribute("msg","Hello session");
    application.setAttribute("msg","Hello application");
    User user = new User(1,"admin","123456","13812345678","江苏-南京");
    request.setAttribute("user",user);

    User user2 = new User(2,"alice","111111","13912345678","江苏-苏州");
    User user3 = new User(3,"jack","222222","13922345678","江苏-泰州");
    List<User> users = new ArrayList<User>();
    users.add(user);
    users.add(user2);
    users.add(user3);
    request.setAttribute("users",users);

    Map<String,User> map = new HashMap<String,User>();
    map.put("u1",user);
    map.put("u2",user2);
    map.put("3",user3);
    request.setAttribute("map",map);
%>

<h2>访问作用域数据</h2>
pageContext:${pageScope.msg}<br>
request:${requestScope.msg}<br>
session:${sessionScope.msg}<br>
application:${applicationScope.msg}<br>
${msg}
${param.name}
<h2>获取应用名</h2>
应用名:<%=request.getContextPath()%><br>
应用名:
<%
    HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
    String path = req.getContextPath();
    out.print(path);
%><br>
应用名:
<%=((HttpServletRequest) pageContext.getRequest()).getContextPath()%><br>
应用名:${pageContext.request.contextPath}
<h2>访问对象信息</h2>
${user}<br>
${user.id}--${user.username}--${user.password}--${user.phone}--${user.address}
<h2>访问list集合</h2>
${users[0].id}-${users[1].username}-${users[2].password}
<h2>访问Map集合</h2>
${map.u1.id}-${map.u2.id}<br>
<!-- 当key是一个纯数字时,不能通过.key的方式访问 -->
${map['3'].id}
<h3>运算</h3>
3+2=${3+2}<br>
3-2=${3-2}<br>
3*2=${3*2}<br>
3/2=${3/2}<br>
3%2=${3%2}<br>
${"admin" eq "admin"}<br>
${"admin" == "admin"}<br>
作用域中是否不存在user:${empty user}<br>
作用域中是否不存在emp:${empty emp}<br>
${3 > 2 && 2 > 3}<br>
${3 > 2 || 2 > 3}<br>
${3 > 2 and 2 > 3}<br>
${3 > 2 or 2 > 3}<br>
${user.username eq "admin" ? "管理员" : "普通员工"}
</body>
</html>
